using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Collections;

namespace TVT.UI.Helpers
{
    public class PageResizer
    {
        public const int minWidth = 1200;
        public const int multiplierOfLenght = 9;
        public static int AdjustmentFactor(int selectedIndex, int count)
        {
            return 1000;
        }

        public static int AdjustmentFactor(int selectedIndex, int count, int fixWidth)
        {            
            int factor = 1;
            if (count == 0)
                count = 1;

            switch (selectedIndex)
            {
                case 0: //mmbtus
                    factor = 230;
                    break;
                case 1: //lots
                    factor = 130;
                    break;
                case 2: //contracts
                    factor = 130;
                    break;
            }

            if (factor * count + fixWidth < minWidth)
            {
                factor = (minWidth - fixWidth) / count;
            }

            return factor;
        }





        public static int AdjustmentFactorFixedContainer(int selectedIndex)
        {
            int factor = 1;

            switch (selectedIndex)
            {
                case 0: //mmbtus
                    factor = 130;
                    break;
                case 1: //lots
                    factor = 100;
                    break;
                case 2: //contracts
                    factor = 100;
                    break;
            }            
            return factor;
        }

        public static int AdjustCellToMin(int width, HtmlControl control, int lenght)
        {            
            int size = lenght * multiplierOfLenght;
            //int size = lenght * Int32.Parse(ConfigurationManager.AppSettings["resize"]);
            int counter = 0;
            bool found = false;
            
            string[] values = control.Style.Value.Split(';');

            foreach (string value in values)
            {
                if(value.Contains("width"))
                {
                    found = true;
                    break;
                }
                counter++;
            }

            int currentSize;

            if (found)
            {
                currentSize = Int32.Parse(values[counter].Replace("width:", "").Replace("px", ""));
            }
            else
            {
                currentSize = 0;
            }

            if (size > currentSize)
            {
                control.Style.Add(HtmlTextWriterStyle.Width, size.ToString() + "px");                    
                width += size - currentSize;                    
            }                                          

            return width;
        }


    }
}
